package cn.edu.cug.cs.gtl.renders.openinventor.paths;

import cn.edu.cug.cs.gtl.apis.render.nodes.BaseKit;
import cn.edu.cug.cs.gtl.apis.render.nodes.Node;
import cn.edu.cug.cs.gtl.apis.render.paths.NodeKitPath;
import cn.edu.cug.cs.gtl.apis.render.paths.Path;
import cn.edu.cug.cs.gtl.renders.openinventor.nodes.NodeImpl;
import com.openinventor.inventor.SoNodeKitPath;
import com.openinventor.inventor.SoPath;
import com.openinventor.inventor.nodekits.SoBaseKit;
import com.openinventor.inventor.nodes.SoNode;

public class NodeKitPathImpl implements NodeKitPath {
    SoNodeKitPath nativeObject = null;

    public NodeKitPathImpl(SoNodeKitPath nativeObject) {
        this.nativeObject = nativeObject;
    }

    @Override
    public Object getNativeObject() {
        return this.nativeObject;
    }

    @Override
    public boolean attach(Object nativeObject) {
        if(nativeObject instanceof SoNodeKitPath){
            this.nativeObject=(SoNodeKitPath) nativeObject;
            return true;
        }
        return false;
    }

    @Override
    public Object detach() {
        SoNodeKitPath p = this.nativeObject;
        this.nativeObject=null;
        return p;
    }

    @Override
    public void append(BaseKit childKit) {
        this.nativeObject.append((SoBaseKit) childKit.getNativeObject());
    }

    @Override
    public void append(Path fromPath) {
        this.nativeObject.append((SoPath) fromPath.getNativeObject());
    }

    @Override
    public boolean containsNode(BaseKit nodekit) {
        return this.nativeObject.containsNode((SoBaseKit) nodekit.getNativeObject());
    }

    @Override
    public boolean containsPath(Path path) {
        return this.nativeObject.containsPath((SoPath) path.getNativeObject());
    }

    @Override
    public int findFork(Path path) {
        return this.nativeObject.findFork((SoPath) path.getNativeObject());
    }

    @Override
    public Node getHead() {
        return new NodeImpl(this.nativeObject.getHead());
    }

    @Override
    public int getLength() {
        return this.nativeObject.getLength();
    }

    @Override
    public Node getNode(int i) {
        return new NodeImpl(this.nativeObject.getNode(i));
    }

    @Override
    public Node getNodeFromTail(int i) {
        return new NodeImpl(this.nativeObject.getNodeFromTail(i));
    }

    @Override
    public Node getTail() {
        return new NodeImpl(this.nativeObject.getTail());
    }

    @Override
    public void pop() {
        this.nativeObject.pop();
    }

    @Override
    public void setHead(Node node) {
        this.nativeObject.setHead((SoNode) node.getNativeObject());
    }

    @Override
    public void truncate(int start) {
        this.nativeObject.truncate(start);
    }
}
